<?php
App::uses('AppModel', 'Model');
/**
 * Modified by Vu 17/05/2013
 *
 * User Model
 *
 * @property Contact $Contact
 * @property Note $Note
 * @property Timesheet $Timesheet
 */
class User extends AppModel {

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'user_id';

    public $validate = array(
        'user_id' => array(
            'notempty' => array(
                'rule' => array('notempty'),
            ),
            'unique_id'=> array(
                'rule'=> 'isUnique',
                'message'=> 'User ID already exists. Please choose a different ID.',
            ),
            'letters_numbers'=> array(
                'rule'=> 'alphaNumeric',
                'message'=> 'Only letters and numbers allowed.',
            ),
            'character_length'=> array(
                'rule' => array('minLength', 4),
                'message' => 'Minimum length of 4 characters must be entered.'
            )
        ),

        'password' => array(
            'notempty' => array(
                'rule' => array('notempty'),
            ),
            'character_length'=> array(
                'rule' => array('minLength', 4),
                'message' => 'Minimum length of 4 characters must be entered.'
            )

        ),

        'contact_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),

        'permission' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),

        'start_date' => array(
            'date' => array(
                'rule' => array('date'),
            ),
            'startEnd'=> array(
                'rule' => 'startDateGreaterEndDate',
                'message' => 'End date cannot be greater than start date.'
            )
        ),

        'Department 1' => array(
            'notempty' => array(
                'rule' => array('notempty'),
            ),
        ),


    );

    public function startDateGreaterEndDate(){
        return $this->data[$this->alias]['start_date'] < $this->data[$this->alias]['end_date'];
    }

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Contact' => array(
			'className' => 'Contact',
			'foreignKey' => 'contact_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'Note' => array(
			'className' => 'Note',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Timesheet' => array(
			'className' => 'Timesheet',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);

}
